package myPack.GMAO.Bean;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import myPack.GMAO.Entity.Contrat;
import myPack.GMAO.Entity.Equipement;
import myPack.GMAO.Interface.ContratInterface;

@Stateless
public class ContratBean implements ContratInterface
{
	@PersistenceContext
	EntityManager em;

	@Override
	public void ajouter(Contrat c) 
	{
		Equipement eq=c.getEquipement();
		eq.setTraiter(true);
		em.merge(eq);
		em.persist(c);
	}
	
	@Override
	public List<Contrat> lister() 
	{
		 return em.createQuery("from Contrat").getResultList();
	}
	
	@Override
	public void supprimer(int idC) 
	{
		em.remove(em.find(Contrat.class,idC));
	}
}
